package com.besidewallpaper.wallpaper.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.besidewallpaper.wallpaper.utils.PageUtils;
import com.besidewallpaper.wallpaper.utils.Query;

import com.besidewallpaper.wallpaper.dao.WallpaperDao;
import com.besidewallpaper.wallpaper.entity.WallpaperEntity;
import com.besidewallpaper.wallpaper.service.WallpaperService;


@Service("wallpaperService")
public class WallpaperServiceImpl extends ServiceImpl<WallpaperDao, WallpaperEntity> implements WallpaperService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<WallpaperEntity> page = this.page(
                new Query<WallpaperEntity>().getPage(params),
                new QueryWrapper<WallpaperEntity>()
        );

        return new PageUtils(page);
    }

    public PageUtils queryPageDesc(Map<String, Object> params) {
        IPage<WallpaperEntity> page = this.page(
                new Query<WallpaperEntity>().getPage(params),
                new QueryWrapper<WallpaperEntity>().orderByDesc("create_time")
        );

        return new PageUtils(page);
    }

    @Override
    public List<WallpaperEntity> query12List() {
        return baseMapper.selectList(Wrappers.<WallpaperEntity>query().orderByDesc("create_time").last("limit 12"));
    }

    @Override
    public List<WallpaperEntity> queryPicTypeList(String picType) {
        return baseMapper.selectList(Wrappers.<WallpaperEntity>query().orderByDesc("create_time").eq("pic_type",picType ));
    }

}